package de.fhwf.mixedreality.agent;

import java.util.ArrayList;
import java.util.List;

import de.fhwf.mixedreality.agent.AbstractBot.ServerType;
import de.fhwf.mixedreality.client.IClient.Team;

public class TeamStarter {
	public static final String 		SERVER 			= "192.168.178.201";
	public static final ServerType 	SERVERTYPE 		= ServerType.Server2008;
	public static final Team 		TEAM 			= Team.YELLOW;
	public static final boolean 	SIMULATION_MODE = false;
	public static final String 		TEAM_NAME 		= "BolzBotz";
	public static final String 		TEAM_NAME2 		= "ParfBotz";
	

	private static List<AbstractBot> mBots;

	public static void main(String[] args) {
		mBots = new ArrayList<AbstractBot>();
		AbstractBot bot;

		// ==== ADD BOTS HERE ====

		System.out.println("[TeamStarter] Starting bot " + 1 + "...");
		bot = new GoalKeepingBot(SERVER, SERVERTYPE, TEAM, 0, 0, "Bot " + 0,
				TEAM_NAME, SIMULATION_MODE);
		bot.start();
		mBots.add(bot);

		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
		}

		System.out.println("[TeamStarter] Starting bot " + 2 + "...");
		bot = new BolzBot(SERVER, SERVERTYPE, TEAM, 1, 1, "Bot " + 1,
				TEAM_NAME, SIMULATION_MODE);
		bot.start();
		mBots.add(bot);

		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
		}
		
		System.out.println("[TeamStarter] Starting bot " + 3 + "...");
		bot = new BolzBot(SERVER, SERVERTYPE, TEAM, 2, 2, "Bot " + 2,
				TEAM_NAME, SIMULATION_MODE);
		bot.start();
		mBots.add(bot);

		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
		}
		
		System.out.println("[TeamStarter] Starting bot " + 4 + "...");
		bot = new GoalKeepingBot(SERVER, SERVERTYPE, Team.BLUE, 3,3, "Bot " + 0,
				TEAM_NAME2, SIMULATION_MODE);
		bot.start();
		mBots.add(bot);

		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
		}
		
		System.out.println("[TeamStarter] Starting bot " + 2 + "...");
		bot = new FieldBot(SERVER, SERVERTYPE, Team.BLUE, 4,4, "Bot " + 1,
				TEAM_NAME2, SIMULATION_MODE);
		bot.start();
		mBots.add(bot);

		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
		}
		
		System.out.println("[TeamStarter] Starting bot " + 2 + "...");
		bot = new FieldBot(SERVER, SERVERTYPE, Team.BLUE, 5, 5, "Bot " + 2,
				TEAM_NAME2, SIMULATION_MODE);
		bot.start();
		mBots.add(bot);

		try {
			Thread.sleep(200);
		} catch (InterruptedException e) {
		}

		// ==== /ADD BOTS HERE ====

		System.out.println("[TeamStarter] Team running!");
		boolean running = true;
		while (running) {
			running = false;
			for (AbstractBot bot2 : mBots) {
				if (bot2.isRunning()) {
					running = true;
				}
			}
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
			}
		}

		for (AbstractBot bot2 : mBots) {
			System.out.println("[TeamStarter] Stopping bot "
					+ bot2.getClient().getBotName() + "...");
			bot2.stop();
		}
		System.out.println("[TeamStarter] Team shut down!");
	}
}
